#ifndef _SERVER_H_
#define _SERVER_H_

#include "CommonMessages.h"
#include "TSSocket.h"
#include <vector>
#include "Player.h"
#include "TSQueue.h"

class Server
{
public:
	Server(unsigned port_num);
	~Server(void);

	// Initialize all server setup
	bool Initialize(void);
	// Run server sending code
	bool Run(void);

	// Helper functions
	// Get number of players that are already connected to the server;
	unsigned short GetNumOfPlayers(void);
	// Get queue task list
	TSQueue<ClientTask>& GetTaskQueue(void) { return mQueue; }

	// Extra thread for receiving packets from all clients
	DWORD WINAPI ReceivingThread(void* param);

private:
	unsigned mPortNum;
	unsigned mNumPlayer;
	static unsigned gameID;
	TSSocket* mServerSocket;

	TSQueue<ClientTask> mQueue;
	std::vector<Player*> mPlayers;

	CRITICAL_SECTION mCSLockServer;
	DWORD mTaskQueueThreadID;
	HANDLE mTaskQueueThreadHandle;
};


#endif
